package com.kczd.jinlan.view.classify;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;

import com.kczd.jinlan.R;
import com.kczd.jinlan.adapter.TabLayoutAdapter;
import com.kczd.jinlan.view.classify.fragment.DefaultFragment;
import com.kczd.jinlan.view.classify.fragment.FromBottomFragment;
import com.kczd.jinlan.view.classify.fragment.FromHighFragment;
import com.kczd.jinlan.view.classify.fragment.TottestFragment;
import com.kczd.jinlan.view.shouye.classActivity.ClassifydetilActivity;

import java.util.ArrayList;
import java.util.List;

/**
 * yang_g
 * 商品筛选页面
 */
public class FoodDetailsActivity extends AppCompatActivity {

    private static final String TAG="FoodDetailsActivity.class";


    private TabLayout tabLayout;
    private ViewPager viewPager;
    private TextView mTitle;

    private List<Fragment> list;
    private String[] titles = {"默认", "最热", "价格从低到高", "价格从高到低"};
    private TabLayoutAdapter adapter;
    public static String classid;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_food_details);

        //从大的分类里面传的id值
        String position=getIntent().getStringExtra("position");

        String groupPosition=getIntent().getStringExtra("groupPosition");
        String classposition=getIntent().getStringExtra("classPosition");

        if(position==null||position.equals(""))
        {
            classid= ClassifydetilActivity.minelist.get(Integer.parseInt(groupPosition)).getClassbaby().get(Integer.parseInt(classposition)).getId();
        }else{
            classid=position;
        }

        initView();

    }

    private void initView() {
        //实例化
        viewPager = (ViewPager)findViewById(R.id.viewpagers);
        tabLayout = (TabLayout)findViewById(R.id.tablayout_food);


        //页面，数据源
        list = new ArrayList<>();
        list.add(new DefaultFragment());//默认
        list.add(new TottestFragment());//最热
        list.add(new FromHighFragment());//从底到高
        list.add(new FromBottomFragment());//从高到底
        //ViewPager的适配器
        adapter = new TabLayoutAdapter(getSupportFragmentManager(), list, titles);
        viewPager.setAdapter(adapter);
        //绑定
        tabLayout.setupWithViewPager(viewPager);
    }
}
